// pages/regist/userredit.js
var utl = require('../../utils/util.js');
var city = require('../../utils/city.js');
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    ischecked: true,
    cantouch: true,
    showbank: false,
    banks: [],
    bindex: 0,
    citys: city.mtData().list,
    pindex: 0,
    cindex: -100,
    showp: false,
    showc: false,

    editcard: '', //身份证号码
    cardNum: '', //银行卡号
    telnum: '' ,//手机号
    showmesscode:false,  //展示手机验证码
    bankms:'', //短信确认码
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    // this.checkbank();
    if (app.globalData.userData) {
      this.setData({
        telnum: app.globalData.telephone,
      })
    }
  },
  //短信确认
  commitbankmess:function(e){
    this.setData({
      bankms:e.detail.value
    })
  },
  //关闭alt
  cancleAlt:function(){
    this.setData({
      showmesscode:false,
    })
  },
  //验证码确认请求
  surebtn:function(){
    var bks = this.data.bankms; //短信确认
    var card = this.data.cardNum;
    if(bks == ''&&bks == undefined){
      wx.showToast({
        title: '短信验证码不能为空',
        icon:'none',
        duration:2000
      })
      return;
    }
    wx.showLoading({
      title: '提交中...',
    })
    utl.serverToken('USER_BINDCARD_CONFIRM', {
      'CARD_NO': card,
      'FRONT_URL': '',
      'SMS_CODE':bks
    }, (err, res) => {
      wx.hideLoading();
      if (err) {
        wx.showToast({
          title: err,
          icon: 'none',
          duration: 2000
        })
        return;
      }
      wx.reLaunch({
        url: '/pages/index/index',
      })
      
    })

  },
 
  //提交
  registAction: function() {
    const isc = this.data.ischecked;
    const cardnum = this.data.cardNum; //卡号
    const edcard = this.data.editcard; //身份证号码
    const tel = this.data.telnum; //手机号
    var that = this;
    var err = '';

    if (!isc) {
      wx.showToast({
        title: '同意服务协议才能注册',
        icon: 'none',
        duration: 2000,
      })
      return;
    }
    if (cardnum == '' || edcard == '' || tel == '') {
      wx.showToast({
        title: '提交的信息不全',
        icon: 'none',
        duration: 2000,
      })
      return;
    }
    var name = this.data.uname;
    var bankname = this.data.bankName;
    wx.showLoading({
      title: '提交中...',
    })
    utl.serverToken('USER_BINDCARD', {
      'CARD_NO': cardnum,
      'ACCOUNT_NAME': name,
      'CARD_TYPE': '2',
      'ID_CARD': edcard,
      'MOBILE': tel,
      'CVN2': '',
      'EXPIRED': ''
    }, (err, res) => {
      wx.hideLoading();
      if (err) {
        wx.showToast({
          title: err,
          icon: 'none',
          duration: 2000
        })
        return;
      }
      if (res.STATUS ==4){
        wx.showModal({
          title: '提示',
          content: res.MSG,
          showCancel:false,
          success(res) {
            that.setData({
              showmesscode: true
            })
          }
        })
      }else{
        wx.reLaunch({
          url: '/pages/index/index',
        })
      }
    })
  },
  usernameAc: function(e) {
    this.setData({
      uname: e.detail.value,
    })
  },
  //手机号
  committel: function(e) {
    this.setData({
      telnum: e.detail.value,
    })
  },
  //绑定身份证号
  commitedit: function(e) {
    this.setData({
      editcard: e.detail.value,
    })
  },
  commitBank: function(e) {
    this.setData({
      bankName: e.detail.value
    })
  },
  //银行卡号
  commitcard: function(e) {
    this.setData({
      cardNum: e.detail.value,
    })
  },
  //选择银行
  bindBankPickerChange: function(e) {
    this.setData({
      bindex: e.detail.value,
      showbank: true
    })
  },
  //绑定省
  bindProvincePickerChange: function(e) {
    this.setData({
      pindex: e.detail.value,
      showp: true,
      cindex: 0,
      cantouch: true
    })
  },
  //选择市区
  bindCityChange: function(e) {
    this.setData({
      cindex: e.detail.value,
      showc: true,

    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  vonfire: function() {
    var check = this.data.ischecked;
    check = !check;
    this.setData({
      ischecked: check
    })
  },
})